package com.liang.threaddemo8;

public class Foodie extends Thread {

    @Override
    public void run() {

        while (true) {
            synchronized (Desk.obj) {
                if (Desk.count <= 0) {
                    break;
                } else {
                    if (Desk.flag) {
                        Desk.count--;
                        System.out.println(Thread.currentThread().getName()+"吃货正在吃汉堡包" + Desk.count);
                        Desk.flag = false;
                        Desk.obj.notify();
                    } else {
                        try {
                            Desk.obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }

            }
        }
    }
}